package dao.impl;

import dao.AddressDao;
import dao.HeaderDao;
import model.Address;
import utils.DaoUtil;
import utils.GenicaDaoImpl;

import java.util.List;

/**
 * @Description: 地址操作实现类
 * @Author one world
 * @Date 2020/9/23 0023 10:41
 */
public class AddressDaoImpl extends GenicaDaoImpl<Address,Integer> implements AddressDao {

    /**
     * 根据用户ID查找其收货地址
     * @param id
     * @return  List<Address>
     */
    @Override
    public List<Address> findByUserId(int id) {
        String sql = "select * from "+ DaoUtil.getTable(Address.class)+" where user_id=?";
        return DaoUtil.queryList(Address.class,sql,id);
    }

    /**
     * 通过订单编号查找地址
     * @param order_no
     * @return Address
     */
    @Override
    public Address findByOrderNo(String order_no) {
        String sql = "select address.* from address left join orders on address.id=orders.address_id where order_no=?";
        return DaoUtil.query(Address.class,sql,order_no);
    }
}
